package solution._0040._0049;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * Created by chen_snow
 * Date: 2021/6/3 22:56
 * Description: 字母异位词分组
 */
public class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {

        HashMap<String, List<String>> listHashMap = new HashMap<>();

        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);

            List<String> list = listHashMap.getOrDefault(new String(chars), new ArrayList<String>());
            list.add(str);
            listHashMap.put(new String(chars), list);
        }

        return new ArrayList<List<String>>(listHashMap.values());
    }
}
